#include<bits/stdc++.h>
using namespace std;
const int N=2001;
const int dx[]={0,0,1,-1};
const int dy[]={1,-1,0,0};
const char sym[]={'R','L','D','U'};
int T,n,m;
char arr[N][N];
char way[N][N];


int main()
{
	int x,y,x1,y1;
	cin>>T;
	for(int i=0;i<T;i++)
	{
		cin>>n>>m;
		string s;
		for(int i1=1;i1<=n;i1++)
		{
			cin>>s;
			for(int j=0;s[j]!='\0';j++)
			{
				arr[i][j+1]=s[j];
			}
		}
		memset(way,0,sizeof(way));
		queue<int> que;
		que.push(1);que.push(1);
		bool suc=false;
		while(!que.empty()&&!suc)
		{
			int size=que.size();
			for(int j=0;!suc&&j<size/2;j++)
			{
				x=que.front();
				que.pop();
				y=que.front();
				que.pop();
				char c=arr[x][y];
				for(int k=0;k<4;k++)
				{
					x1=x+dx[k];
					y1=y+dy[k];
					if(x1>0&&x1<=n&&y1>0&&y1<=m
					&&c!=arr[x1][y1]&&way[x1][y1]==0)
					{
						way[x1][y1]=sym[k];
						que.push(x1);que.push(y1);
					}
					if(x1==n&&y1==m)
					{
						suc=true;
						break;
					}
				}
			}
		}
		if(way[n][m]==0)
		{
			cout<<"-1"<<endl;	
		}
		else{
			int x2=n,y2=m;
			string s;
			int step=0;
			while(!(x2==1&&y2==1))
			{
				s=way[x2][y2]+s;
				if(way[x2][y2]=='U'){
					x2++;
				}
				else if(way[x2][y2]=='D')
				{
					x2--;
				}
				else if(way[x2][y2]=='L')
				{
					y2++;
				}
				else if(way[x2][y2]=='R')
				{
					y2--;
				}
				step++;
			}
			cout<<step<<endl;
			cout<<s<<endl;
		}
	}
	return 0;
} 
